import request from '@/utils/request.js'

const goods = {
  // 获取商品分类
  getCatesApi(params) {
    return request.get('/categories',
      { params })
  },
  postCateApi(data) {
    return request.post('/categories', data)
  },
  putCateApi(id, catName) {
    return request.put(`/categories/${id}`, {
      cat_name: catName
    })
  },
  deleteCateApi(id) {
    return request.delete(`/categories/${id}`)
  },
  // 获取分类参数
  getAttributesApi(id, sel) {
    return request.get(`/categories/${id}/attributes`, {
      params: {
        sel
      }
    }
    )
  },
  // 添加分类参数
  postAttributesApi(id, data) {
    return request.post(`categories/${id}/attributes`, data)
  },
  // 删除分类参数
  deleteAttributesApi(id, attrid) {
    return request.delete(`categories/${id}/attributes/${attrid}`)
  },
  // 修改分类参数
  putAttributesApi(id, attrid, data) {
    return request.put(`categories/${id}/attributes/${attrid}`, data)
  },

  // 获取商品列表
  getGoodsApi(params) {
    return request.get('/goods', { params })
  },
  // 删除商品
  deleteGoodsApi(id) {
    return request.delete(`/goods/${id}`)
  },
  // 添加商品
  postGoodsApi(data) {
    return request.post('/goods', data)
  },
  // 根据id获取商品信息
  getGoodById(id) {
    return request.get('/goods/' + id)
  },
  // 修改商品
  putGoodsApi(id, data) {
    return request.put('/goods/' + id, data)
  }
}
export default goods
